﻿#include "CPdfRptBaCamOperBase.h"
#include "HeaderFile.h"

CPdfRptBaCamOperBase::CPdfRptBaCamOperBase(CPdfRptTool *pPdfRptTool, QObject *parent)
	: QObject(parent)
{
	m_pPdfRptTool = pPdfRptTool;
}

CPdfRptBaCamOperBase::~CPdfRptBaCamOperBase()
{

}

//绘制球机检测综述表格
bool CPdfRptBaCamOperBase::drawBaCamOverviewForm(double &dStartRow, double &dStartCol, CAllPdfRptDataInfo &dataInfo, QPainter &painter, QPrinter &printer, QString &sErrMsg)
{
	if (m_pPdfRptTool == nullptr)
	{
		return false;
	}

	//判断是否需要换页画
	int nNeedRows = 6;
	m_pPdfRptTool->judgeExecAutoPageChg(dStartRow, dStartCol, nNeedRows, printer, sErrMsg);

	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev24Bold, enPdfRptPenBlack);//设置字体和画笔等级
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 4, 2, A2T("球机检测"), painter, printer, sErrMsg);//绘制表格附带文字-->表名称(球机检测)

	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("检测日期"), painter, printer, sErrMsg);//绘制表格附带文字-->检测日期
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 3, 1, dataInfo.bacamDataInfo.m_sDetTime, painter, printer, sErrMsg);//绘制表格附带文字-->检测日期

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("报警项数"), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 3, 1, QString::number(dataInfo.bacamDataInfo.m_nAlmCount), painter, printer, sErrMsg);//绘制表格附带文字-->报警项数

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("检测开始时间"), painter, printer, sErrMsg);//绘制表格附带文字-->检测开始时间
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, dataInfo.bacamDataInfo.m_sDetStartTime, painter, printer, sErrMsg);//绘制表格附带文字-->检测开始时间

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("检测结束时间"), painter, printer, sErrMsg);//绘制表格附带文字-->检测结束时间
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, dataInfo.bacamDataInfo.m_sDetEndTime, painter, printer, sErrMsg);//绘制表格附带文字-->检测结束时间

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("备注"), painter, printer, sErrMsg);//绘制表格附带文字-->备注
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 3, 1, dataInfo.bacamDataInfo.m_sComment, painter, printer, sErrMsg);//绘制表格附带文字-->备注

	return true;
}

//绘制球机所有报警详情
bool CPdfRptBaCamOperBase::drawBaCamAllAlmDes(double &dStartRow, double &dStartCol, CAllPdfRptDataInfo &dataInfo, QPainter &painter, QPrinter &printer, QString &sErrMsg)
{
	if (dataInfo.bacamDataInfo.m_vecFormBaCamAlmInfo.size() == 0)
	{
		return true;
	}

	//遍历Vec容器
	for (int nIndex = 0; nIndex < dataInfo.bacamDataInfo.m_vecFormBaCamAlmInfo.size(); nIndex++)
	{
		if (0 == nIndex)
		{
			printer.newPage();//添加新的一页 第一个声振温报警需强制换页开始显示
			dStartRow = 0;
			dStartCol = 0;

			//绘制详述表头
			drawBaCamAlmDesHeader(dStartRow, dStartCol, painter, printer, sErrMsg);
		}

		draBaCamSingAlmDes(dStartRow, dStartCol, nIndex, dataInfo.bacamDataInfo.m_vecFormBaCamAlmInfo[nIndex], painter, printer, sErrMsg);//绘制单个球机报警详情(不包含表头)
		dStartRow += 1;//间隔一行再画下一组
	}
}

//绘制单个球机报警详情(不包含表头)
bool CPdfRptBaCamOperBase::draBaCamSingAlmDes(double &dStartRow, double &dStartCol, int nAlmIdex, CPdfBaCamSglAlmInfo &sglAlmInfo, QPainter &painter, QPrinter &printer, QString &sErrMsg)
{
	if (m_pPdfRptTool == nullptr)
	{
		return false;
	}

	//判断是否需要换页画
	int nNeedRows = 9;
	m_pPdfRptTool->judgeExecAutoPageChg(dStartRow, dStartCol, nNeedRows, printer, sErrMsg);

	//m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev24Bold, enPdfRptPenBlack);//设置字体和画笔等级
	//m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 4, 2, A2T("球机检测"), painter, printer, sErrMsg);//绘制表格附带文字-->表名称(皮带名称)

	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev18, enPdfRptPenBlack);//设置字体和画笔等级

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("序号"), painter, printer, sErrMsg);//绘制表格附带文字-->序号
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, QString::number(nAlmIdex + 1), painter, printer, sErrMsg);//绘制表格附带文字-->序号

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("时间"), painter, printer, sErrMsg);//绘制表格附带文字-->时间
	
	if (sglAlmInfo.m_sAlmTime.isEmpty())
	{
		m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("/"), painter, printer, sErrMsg);
	}
	else
	{
		m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, sglAlmInfo.m_sAlmTime, painter, printer, sErrMsg);//绘制表格附带文字-->时间 1
	}
	

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("状态"), painter, printer, sErrMsg);//绘制表格附带文字-->状态
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, sglAlmInfo.m_nAlmType == 0 ? A2T("正常"): A2T("报警"), painter, printer, sErrMsg);//绘制表格附带文字-->状态

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("阈值"), painter, printer, sErrMsg);//绘制表格附带文字-->阈值
	QString sDataThresholdH = A2T("高限%1℃").arg(QString::number(sglAlmInfo.m_dDataThresholdH, 'f', 1));
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, sDataThresholdH, painter, printer, sErrMsg);//绘制表格附带文字-->阈值 2

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("球机名称"), painter, printer, sErrMsg);//绘制表格附带文字-->球机名称
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 3, 1, sglAlmInfo.m_sBaCamName, painter, printer, sErrMsg);//绘制表格附带文字-->球机名称 3

	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 1, A2T("巡检项名称"), painter, printer, sErrMsg);//绘制表格附带文字-->巡检项名称
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 3, 1, sglAlmInfo.m_sBaCamItemName, painter, printer, sErrMsg);//绘制表格附带文字-->巡检项名称 4

	//绘制报警图片
	//先绘制左侧合并的单元格
	double dTempStartRow = dStartRow;
	double dTempStartCol = dStartCol;
	m_pPdfRptTool->drawFormAttachText(dTempStartRow, dTempStartCol, 1, 5, A2T("球机定点巡检照片"), painter, printer, sErrMsg);
	//再绘制右边图片
	dTempStartRow = dStartRow;
	dTempStartCol = dStartCol;
	dTempStartCol += 1;
	QPixmap pixmapNow(sglAlmInfo.m_sLocPicPath);
	m_pPdfRptTool->drawFormAttachPic(dTempStartRow, dTempStartCol, 2, 5, pixmapNow, painter, printer, sErrMsg);

	//最后绘制最右侧图片描述
	dStartCol += 3;
	QString sPicDesc = A2T("平均温度:%1℃\n最低温度:%2℃\n最高温度:%3℃").arg(QString::number(sglAlmInfo.m_dAvgTemp, 'f', 1)).arg(QString::number(sglAlmInfo.m_dMinTemp, 'f', 1)).arg(QString::number(sglAlmInfo.m_dMaxTemp, 'f', 1));
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 1, 5, sPicDesc, painter, printer, sErrMsg);//绘制表格附带文字-->图片描述
	
}
bool CPdfRptBaCamOperBase::drawBaCamAlmDesHeader(double & dStartRow, double & dStartCol, QPainter & painter, QPrinter & printer, QString & sErrMsg)
{
	if (m_pPdfRptTool == nullptr)
	{
		return false;
	}

	//判断是否需要换页画
	int nNeedRows = 2;
	m_pPdfRptTool->judgeExecAutoPageChg(dStartRow, dStartCol, nNeedRows, printer, sErrMsg);

	m_pPdfRptTool->setFontAndPenLevel(enPdfRptFontLev24Bold, enPdfRptPenBlack);//设置字体和画笔等级
	QString sTitle = A2T("%1").arg(A2T("球机定点巡检"));
	m_pPdfRptTool->drawFormAttachText(dStartRow, dStartCol, 4, 2, sTitle, painter, printer, sErrMsg);//绘制表格附带文字-->表名称(球机定点巡检)
	return true;
}

